/*     */ package blockbuster.emitter;
/*     */ 
/*     */ import blockbuster.components.appearance.BedrockComponentCollisionAppearance;
/*     */ import blockbuster.components.appearance.BedrockComponentCollisionTinting;
/*     */ import blockbuster.math.molang.expressions.MolangExpression;
/*     */ import blockbuster.utils.MatrixUtils;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import javax.vecmath.Matrix3f;
/*     */ import javax.vecmath.SingularMatrixException;
/*     */ import javax.vecmath.Tuple3d;
/*     */ import javax.vecmath.Tuple3f;
/*     */ import javax.vecmath.Vector3d;
/*     */ import javax.vecmath.Vector3f;
/*     */ import net.minecraft.entity.Entity;
/*     */ 
/*     */ public class BedrockParticle
/*     */ {
/*  19 */   public float random1 = (float)Math.random();
/*  20 */   public float random2 = (float)Math.random();
/*  21 */   public float random3 = (float)Math.random();
/*  22 */   public float random4 = (float)Math.random();
/*     */   
/*     */   public int age;
/*     */   
/*     */   public int lifetime;
/*     */   
/*     */   public boolean dead;
/*     */   
/*     */   public boolean relativePosition;
/*     */   public boolean relativeRotation;
/*     */   public boolean relativeDirection;
/*     */   public boolean relativeScale;
/*     */   public boolean relativeScaleBillboard;
/*     */   public boolean relativeAcceleration;
/*     */   public boolean realisticCollisionDrag;
/*     */   public float linearVelocity;
/*     */   public float angularVelocity;
/*     */   public boolean gravity;
/*     */   public boolean manual;
/*  41 */   private int expireAge = -1;
/*     */   
/*  43 */   private int expirationDelay = -1;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*  52 */   public Vector3f collisionTime = new Vector3f(-2.0F, -2.0F, -2.0F);
/*  53 */   public HashMap<Entity, Vector3f> entityCollisionTime = new HashMap<>();
/*     */ 
/*     */   
/*     */   public boolean collided;
/*     */   
/*     */   public int bounces;
/*     */   
/*  60 */   public int firstIntersection = -1;
/*     */   
/*     */   public boolean intersected;
/*     */   
/*     */   public float rotation;
/*     */   
/*     */   public float initialRotation;
/*     */   
/*     */   public float prevRotation;
/*     */   
/*     */   public float rotationVelocity;
/*     */   public float rotationAcceleration;
/*     */   public float rotationDrag;
/*  73 */   public Vector3d offset = new Vector3d();
/*     */   
/*  75 */   public Vector3d position = new Vector3d();
/*  76 */   public Vector3d initialPosition = new Vector3d();
/*  77 */   public Vector3d prevPosition = new Vector3d();
/*  78 */   public Matrix3f matrix = new Matrix3f();
/*     */   
/*     */   private boolean matrixSet;
/*  81 */   public Vector3f speed = new Vector3f();
/*  82 */   public Vector3f acceleration = new Vector3f();
/*  83 */   public Vector3f accelerationFactor = new Vector3f(1.0F, 1.0F, 1.0F);
/*  84 */   public float drag = 0.0F;
/*  85 */   public float dragFactor = 0.0F;
/*     */ 
/*     */   
/*  88 */   public float r = 1.0F;
/*  89 */   public float g = 1.0F;
/*  90 */   public float b = 1.0F;
/*  91 */   public float a = 1.0F;
/*     */   
/*  93 */   private Vector3d global = new Vector3d();
/*     */ 
/*     */   
/*     */   public BedrockParticle() {
/*  97 */     this.speed.set((float)Math.random() - 0.5F, (float)Math.random() - 0.5F, (float)Math.random() - 0.5F);
/*  98 */     this.speed.normalize();
/*  99 */     this.matrix.setIdentity();
/*     */   }
/*     */ 
/*     */   
/*     */   public boolean isCollisionTexture(BedrockEmitter emitter) {
/* 104 */     return (MolangExpression.isOne(((BedrockComponentCollisionAppearance)emitter.scheme.getOrCreate(BedrockComponentCollisionAppearance.class)).enabled) && this.intersected);
/*     */   }
/*     */ 
/*     */   
/*     */   public boolean isCollisionTinting(BedrockEmitter emitter) {
/* 109 */     return (MolangExpression.isOne(((BedrockComponentCollisionTinting)emitter.scheme.getOrCreate(BedrockComponentCollisionTinting.class)).enabled) && this.intersected);
/*     */   }
/*     */ 
/*     */   
/*     */   public int getExpireAge() {
/* 114 */     return this.expireAge;
/*     */   }
/*     */ 
/*     */   
/*     */   public int getExpirationDelay() {
/* 119 */     return this.expirationDelay;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public BedrockParticle softCopy(BedrockParticle to) {
/* 129 */     to.age = this.age;
/* 130 */     to.expireAge = this.expireAge;
/* 131 */     to.expirationDelay = this.expirationDelay;
/* 132 */     to.realisticCollisionDrag = this.realisticCollisionDrag;
/* 133 */     to.collisionTime = (Vector3f)this.collisionTime.clone();
/* 134 */     to.entityCollisionTime = new HashMap<>();
/*     */     
/* 136 */     for (Map.Entry<Entity, Vector3f> entry : this.entityCollisionTime.entrySet())
/*     */     {
/* 138 */       to.entityCollisionTime.put(entry.getKey(), (Vector3f)((Vector3f)entry.getValue()).clone());
/*     */     }
/*     */     
/* 141 */     to.bounces = this.bounces;
/* 142 */     to.firstIntersection = this.firstIntersection;
/* 143 */     to.offset = (Vector3d)this.offset.clone();
/* 144 */     to.position = (Vector3d)this.position.clone();
/* 145 */     to.initialPosition = (Vector3d)this.initialPosition.clone();
/* 146 */     to.prevPosition = (Vector3d)this.prevPosition.clone();
/* 147 */     to.matrix = (Matrix3f)this.matrix.clone();
/* 148 */     to.matrixSet = this.matrixSet;
/* 149 */     to.speed = (Vector3f)this.speed.clone();
/* 150 */     to.acceleration = (Vector3f)this.acceleration.clone();
/* 151 */     to.accelerationFactor = (Vector3f)this.accelerationFactor.clone();
/* 152 */     to.dragFactor = this.dragFactor;
/* 153 */     to.global = (Vector3d)this.global.clone();
/*     */     
/* 155 */     return to;
/*     */   }
/*     */ 
/*     */   
/*     */   public double getDistanceSq(BedrockEmitter emitter) {
/* 160 */     Vector3d pos = getGlobalPosition(emitter);
/*     */     
/* 162 */     double dx = emitter.cX - pos.x;
/* 163 */     double dy = emitter.cY - pos.y;
/* 164 */     double dz = emitter.cZ - pos.z;
/*     */     
/* 166 */     return dx * dx + dy * dy + dz * dz;
/*     */   }
/*     */ 
/*     */   
/*     */   public double getAge(float partialTick) {
/* 171 */     return (this.age + partialTick) / 20.0D;
/*     */   }
/*     */ 
/*     */   
/*     */   public Vector3d getGlobalPosition(BedrockEmitter emitter) {
/* 176 */     return getGlobalPosition(emitter, this.position);
/*     */   }
/*     */ 
/*     */   
/*     */   public Vector3d getGlobalPosition(BedrockEmitter emitter, Vector3d vector) {
/* 181 */     double px = vector.x;
/* 182 */     double py = vector.y;
/* 183 */     double pz = vector.z;
/*     */     
/* 185 */     if (this.relativePosition && this.relativeRotation) {
/*     */       
/* 187 */       Vector3f v = new Vector3f((float)px, (float)py, (float)pz);
/* 188 */       emitter.rotation.transform((Tuple3f)v);
/*     */       
/* 190 */       px = v.x;
/* 191 */       py = v.y;
/* 192 */       pz = v.z;
/*     */       
/* 194 */       px += emitter.lastGlobal.x;
/* 195 */       py += emitter.lastGlobal.y;
/* 196 */       pz += emitter.lastGlobal.z;
/*     */     } 
/*     */     
/* 199 */     this.global.set(px, py, pz);
/*     */     
/* 201 */     return this.global;
/*     */   }
/*     */ 
/*     */   
/*     */   public void update(BedrockEmitter emitter) {
/* 206 */     this.prevRotation = this.rotation;
/* 207 */     this.prevPosition.set((Tuple3d)this.position);
/*     */     
/* 209 */     setupMatrix(emitter);
/*     */     
/* 211 */     if (!this.manual) {
/*     */ 
/*     */ 
/*     */       
/* 215 */       if (this.realisticCollisionDrag && Math.round(this.speed.x * 10000.0F) == 0 && Math.round(this.speed.y * 10000.0F) == 0 && Math.round(this.speed.z * 10000.0F) == 0) {
/*     */         
/* 217 */         this.dragFactor = 0.0F;
/* 218 */         this.speed.scale(0.0F);
/*     */       } 
/*     */ 
/*     */       
/* 222 */       if (this.entityCollisionTime.isEmpty()) {
/*     */         
/* 224 */         transformOffsetToGlobal();
/*     */       }
/*     */       else {
/*     */         
/* 228 */         for (Map.Entry<Entity, Vector3f> entry : this.entityCollisionTime.entrySet()) {
/*     */           
/* 230 */           if (((Vector3f)entry.getValue()).y != this.age)
/*     */           {
/* 232 */             transformOffsetToGlobal();
/*     */           }
/*     */         } 
/*     */       } 
/*     */       
/* 237 */       float rotationAcceleration = this.rotationAcceleration / 20.0F - this.rotationDrag * this.rotationVelocity;
/* 238 */       this.rotationVelocity += rotationAcceleration / 20.0F;
/* 239 */       this.rotation = this.initialRotation + this.rotationVelocity * this.age;
/*     */ 
/*     */       
/* 242 */       if (this.age == 0) {
/*     */         
/* 244 */         if (this.relativeDirection)
/*     */         {
/* 246 */           emitter.rotation.transform((Tuple3f)this.speed);
/*     */         }
/*     */         
/* 249 */         if (this.linearVelocity != 0.0F) {
/*     */           
/* 251 */           Vector3f v = new Vector3f(emitter.lastGlobal);
/* 252 */           v.x = (float)(v.x - emitter.prevGlobal.x);
/* 253 */           v.y = (float)(v.y - emitter.prevGlobal.y);
/* 254 */           v.z = (float)(v.z - emitter.prevGlobal.z);
/*     */           
/* 256 */           this.speed.x += v.x * this.linearVelocity;
/* 257 */           this.speed.y += v.y * this.linearVelocity;
/* 258 */           this.speed.z += v.z * this.linearVelocity;
/*     */         } 
/*     */         
/* 261 */         if (this.angularVelocity != 0.0F) {
/*     */           
/* 263 */           Matrix3f rotation1 = new Matrix3f(emitter.rotation);
/* 264 */           Matrix3f identity = new Matrix3f();
/*     */           
/* 266 */           identity.setIdentity();
/*     */ 
/*     */           
/*     */           try {
/* 270 */             Matrix3f rotation0 = new Matrix3f(emitter.prevRotation);
/*     */             
/* 272 */             rotation0.invert();
/* 273 */             rotation1.mul(rotation0);
/*     */             
/* 275 */             Vector3f angularV = MatrixUtils.getAngularVelocity(rotation1);
/*     */             
/* 277 */             Vector3f radius = new Vector3f(emitter.translation);
/* 278 */             radius.x = (float)(radius.x + this.position.x - emitter.lastGlobal.x);
/* 279 */             radius.y = (float)(radius.y + this.position.y - emitter.lastGlobal.y);
/* 280 */             radius.z = (float)(radius.z + this.position.z - emitter.lastGlobal.z);
/*     */             
/* 282 */             Vector3f v = new Vector3f();
/*     */             
/* 284 */             v.cross(angularV, radius);
/*     */             
/* 286 */             this.speed.x += v.x * this.angularVelocity;
/* 287 */             this.speed.y += v.y * this.angularVelocity;
/* 288 */             this.speed.z += v.z * this.angularVelocity;
/*     */           }
/* 290 */           catch (SingularMatrixException singularMatrixException) {}
/*     */         } 
/*     */       } 
/*     */       
/* 294 */       if (this.relativeAcceleration)
/*     */       {
/* 296 */         emitter.rotation.transform((Tuple3f)this.acceleration);
/*     */       }
/*     */       
/* 299 */       Vector3f drag = new Vector3f(this.speed);
/*     */       
/* 301 */       drag.scale(-(this.drag + this.dragFactor));
/*     */       
/* 303 */       if (this.gravity)
/*     */       {
/* 305 */         this.acceleration.y = (float)(this.acceleration.y - 9.81D);
/*     */       }
/*     */       
/* 308 */       this.acceleration.add((Tuple3f)drag);
/* 309 */       this.acceleration.scale(0.05F);
/* 310 */       this.speed.add((Tuple3f)this.acceleration);
/*     */       
/* 312 */       Vector3f speed0 = new Vector3f(this.speed);
/* 313 */       speed0.x *= this.accelerationFactor.x;
/* 314 */       speed0.y *= this.accelerationFactor.y;
/* 315 */       speed0.z *= this.accelerationFactor.z;
/*     */       
/* 317 */       if (this.relativePosition || this.relativeRotation)
/*     */       {
/* 319 */         this.matrix.transform((Tuple3f)speed0);
/*     */       }
/*     */       
/* 322 */       this.position.x += (speed0.x / 20.0F);
/* 323 */       this.position.y += (speed0.y / 20.0F);
/* 324 */       this.position.z += (speed0.z / 20.0F);
/*     */     } 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */     
/* 336 */     if (this.lifetime >= 0 && (this.age >= this.lifetime || (this.age >= this.expireAge && this.expireAge != -1)))
/*     */     {
/*     */       
/* 339 */       this.dead = true;
/*     */     }
/*     */     
/* 342 */     this.age++;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public void setExpirationDelay(double delay) {
/* 350 */     int expirationDelay = (int)delay;
/*     */     
/* 352 */     if (this.age + expirationDelay < this.expireAge || this.expireAge == -1) {
/*     */       
/* 354 */       this.expirationDelay = Math.abs(expirationDelay);
/* 355 */       this.expireAge = this.age + this.expirationDelay;
/*     */     } 
/*     */   }
/*     */ 
/*     */   
/*     */   public void setupMatrix(BedrockEmitter emitter) {
/* 361 */     if (this.relativePosition) {
/*     */       
/* 363 */       if (this.relativeRotation)
/*     */       {
/* 365 */         this.matrix.setIdentity();
/*     */       }
/* 367 */       else if (!this.matrixSet)
/*     */       {
/* 369 */         this.matrix.set(emitter.rotation);
/* 370 */         this.matrixSet = true;
/*     */       }
/*     */     
/* 373 */     } else if (this.relativeRotation) {
/*     */       
/* 375 */       this.matrix.set(emitter.rotation);
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public void transformOffsetToGlobal() {
/* 385 */     this.offset.scale(6.0D);
/*     */     
/* 387 */     this.speed.x = (float)(this.speed.x + this.offset.x);
/* 388 */     this.speed.y = (float)(this.speed.y + this.offset.y);
/* 389 */     this.speed.z = (float)(this.speed.z + this.offset.z);
/*     */     
/* 391 */     this.offset.scale(0.0D);
/*     */   }
/*     */ }


/* Location:              D:\fanbian\[D][龙之核心]DragonCore-2.6.0.3.jar!\blockbuster\emitter\BedrockParticle.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */